package j07arraylist;

import java.util.*;

public class J3 {
    public static void main(String[] args) {
//        List<String> l1 = Arrays.asList("a","b","c");
        List<String> l1 = new ArrayList<>(
                Arrays.asList("a","b","c")
        );
//        l1.remove(0);
//        System.out.println("l1 = " + l1);

        Iterator<String> it = l1.iterator();
        while (it.hasNext()){
            String s = it.next();
            if(s.equals("a")){
//                l1.remove(s);
                it.remove();
            }
        }
        System.out.println("l1 = " + l1);
    }
}

class J4Sort{
    public static void main(String[] args) {
        List<String> l1 = new ArrayList<>(
                Arrays.asList("z","b","c","x","m")
        );
//        l1.sort(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                //a-z
////                return o1.compareTo(o2);
//                //z-a
//                return o2.compareTo(o1);
//            }
//        });
        l1.sort((s1,s2)->s1.compareTo(s2));
        System.out.println("l1 = " + l1);

        System.out.println("====");
        List<Integer> arr2 = new ArrayList<>(
                Arrays.asList(3,5,1,7,2,8,4)
        );
//        arr2.sort((num1,num2)-> num1.compareTo(num2));
        arr2.sort((num1,num2)-> num2-num1);
        System.out.println("arr2 = " + arr2);
    }
}

class Man{
    String name;

    public Man(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Man{" +
                "name='" + name + '\'' +
                '}';
    }
}
class J5Objectsort{
    public static void main(String[] args) {
        List<Man> arr1 = new ArrayList<>(
                Arrays.asList(
                        new Man("jack"),
                        new Man("lack"),
                        new Man("mack"),
                        new Man("zack"),
                        new Man("aack")
                )
        );
        arr1.sort((m1,m2)->{
            return m1.name.compareTo(m2.name);
        });
        System.out.println("arr1 = " + arr1);
    }
}